/**
 * Team CJRR ECE 448/449 Senior Design Project
 * for Miami University, Spring & Fall 2013
 *
 * Multifunction Utility Glove
 * - Non-Contact Voltage Sensor
 * - Stud Sensor
 * - Flashlight
 * - Laser Pointer
 */

/**
 * Copyrights and licenses to go here.
 */

#define DEBUG
#include "config.h"
#include "debug.h"
#include "state.h"
#include "standby_state.h"
#include "volt_sensor_state.h"


standby_state standby_s;
volt_sensor_state volt_sensor_s(volt_sensor_pin);


void setup()
{
   #ifdef DEBUG
      Serial.begin(9600);
   #endif

   pinMode(laser_pin, OUTPUT);
   digitalWrite(laser_pin, LOW);
   pinMode(light_pin, OUTPUT);
   digitalWrite(light_pin, LOW);
   pinMode(speaker_pin, OUTPUT);
   digitalWrite(speaker_pin, LOW);
   pinMode(status_green_pin, OUTPUT);
   digitalWrite(status_green_pin, LOW);
   pinMode(status_red_pin, OUTPUT);
   digitalWrite(status_red_pin, LOW);

   state::set_next(&standby_s);
}


void loop()
{
   int16_t hand_value = analogRead(hand_sensor_pin);
   DEBUG_PRINT("hand_value = ");
   DEBUG_PRINTDEC(hand_value);
   DEBUG_PRINTLN();

   if (hand_value >= (wakeup_value - wakeup_range) &&
       hand_value <= (wakeup_value + wakeup_range)) {
      state::set_next(&volt_sensor_s);
   }
   else {
      state::set_next(&standby_s);
   }

   state::update();
}

